package com.ruyuan.eshop.construction.service.impl;

import com.ruyuan.eshop.common.core.PageResult;
import com.ruyuan.eshop.construction.domain.dto.BuyerInfoDTO;
import com.ruyuan.eshop.construction.domain.dto.BuyerListDTO;
import com.ruyuan.eshop.construction.domain.dto.BuyerResultDTO;
import com.ruyuan.eshop.construction.domain.request.BuyerRequest;
import com.ruyuan.eshop.construction.domain.request.QueryBuyerListRequest;
import com.ruyuan.eshop.construction.domain.request.QueryBuyerPageRequest;
import com.ruyuan.eshop.construction.repository.BuyerRepository;
import com.ruyuan.eshop.construction.service.BuyerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 买手服务
 *
 * @author zhonghuashishan
 */
@Service
public class BuyerServiceImpl implements BuyerService {

    @Resource
    private BuyerRepository buyerRepository;

    @Override
    public BuyerResultDTO saveBuyer(BuyerRequest buyerRequest) {
        // 保存买手信息
        buyerRepository.saveOrUpdate(buyerRequest);
        // 返回结果信息
        return new BuyerResultDTO(Boolean.TRUE);
    }

    @Override
    public BuyerListDTO getBuyerInfo(QueryBuyerListRequest queryBuyerListRequest) {
        List<BuyerInfoDTO> buyerInfoDTOS = buyerRepository.listBuyerInfo(queryBuyerListRequest);
        // 返回信息
        return new BuyerListDTO(buyerInfoDTOS);
    }

    @Override
    public PageResult<BuyerInfoDTO> getBuyerInfoPage(QueryBuyerPageRequest queryBuyerPageRequest) {
        return buyerRepository.pageResult(queryBuyerPageRequest);
    }
}
